<template>
  <!-- 外层容器 -->
  <el-container>
    <!-- 侧边栏容器 -->
    <el-aside>
      <el-menu :collapse="hiddenSide" :default-active="activeIndex" unique-opened background-color="#304156"
        text-color="#BFCBD9" style="border-right: none" class="el-menu-vertical-demo" active-text-color="#409EFF"
        @select="activeChange" router>
        <el-menu-item index="/home">
          <i class="el-icon-s-home"></i>
          <span slot="title">网站主页</span>
        </el-menu-item>
        <!-- <el-menu-item index="/charge">收费标准管理</el-menu-item> -->
        <el-submenu v-if="role == 1" index="2">
          <template slot="title">
            <i class="el-icon-delete-solid"></i>
            <span>系统管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/user">用户管理</el-menu-item>
            <el-menu-item index="/notice">公告管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu v-if="role != 3" index="3">
          <template slot="title">
            <i class="el-icon-s-goods"></i>
            <span>师资管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/consult">咨询师管理</el-menu-item>
            <el-menu-item v-if="role == 1" index="/consultlever">咨询师等级管理</el-menu-item>
            <el-menu-item v-if="role == 1" index="/specialty">擅长领域管理</el-menu-item>
            <el-menu-item index="/charge">收费标准管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="4">
          <template slot="title">
            <i class="el-icon-s-open"></i>
            <span>内容管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item v-if="role != 3" index="/article">文章管理</el-menu-item>
            <el-menu-item v-if="role != 3" index="/articletype">文章分类管理</el-menu-item>
            <el-menu-item v-if="role != 3" index="course">课程管理</el-menu-item>
            <el-menu-item v-if="role != 3" index="coursetype">课程分类管理</el-menu-item>
            <el-menu-item index="question">心理答疑管理</el-menu-item>
            <el-menu-item v-if="role != 3" index="/coursemark">课程评价管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="5">
          <template slot="title">
            <i class="el-icon-s-open"></i>
            <span>知识管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item v-if="role != 3" index="/heartknowledge">心理知识管理</el-menu-item>
            <el-menu-item v-if="role != 3" index="/hearttest">心理测评试题管理</el-menu-item>
            <el-menu-item v-if="role != 3" index="/heartMark">心理测评管理</el-menu-item>
            <el-menu-item index="/fm">FM管理</el-menu-item>
            <el-menu-item index="/free">公益内容管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-menu-item v-if="role != 2" index="/company">
          <i class="el-icon-s-flag"></i>
          <span slot="title">公司信息管理</span>
        </el-menu-item>
        <!-- <el-menu-item index="7">
          <i class="el-icon-s-management"></i>
          <span slot="title">用户评价管理</span>
        </el-menu-item> -->

        <el-submenu index="6">
          <template slot="title">
            <i class="el-icon-s-open"></i>
            <span>咨询管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/appointmentManager">咨询预约管理</el-menu-item>
            <!-- <el-menu-item index="4-4">咨询回复管理</el-menu-item> -->
            <el-menu-item index="/usermark">用户评价管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu v-if="role != 3" index="7">
          <template slot="title">
            <i class="el-icon-s-open"></i>
            <span>回复表</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="/reply">回复管理</el-menu-item>
            <el-menu-item index="/coursereply">课程回复管理</el-menu-item>
            <el-menu-item index="/coursetalk">课程交流管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- 顶栏容器 -->
      <el-header>
        <div class="header-left">
          <i v-if="hiddenSide" @click="showSide" class="el-icon-s-unfold icon"></i>
          <i v-else @click="showSide" class="el-icon-s-fold icon"></i>
        </div>
        <div class="header-right">
          <!-- @command：是函数，专门处理下拉框中的请求事件的  -->
          <el-dropdown @command="handleCommand" trigger="click">
            <span class="el-dropdown-link">
              <img :src="userInfo ? baseUrl + 'downLoad?filename=' + userInfo.img :'../assets/logo.png'" alt="" /> 你好,
              {{ username }}
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="userInfo">个人中心</el-dropdown-item>
              <!-- <el-dropdown-item command="system">系统设置</el-dropdown-item> -->
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <!-- 主要区域容器 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { url } from '@/util/tools';
export default {
  data() {
    return {
      username: "",

      //侧边栏收缩判断
      hiddenSide: false,

      //侧边栏活动页高亮
      activeIndex: "/",
      userInfo:null,
      baseUrl: url,
      role: null,
    };
  },
  mounted() {
    this.username = sessionStorage.getItem("nickname");
    this.activeIndex = this.$route.path;
    // console.log(this.activeIndex);
    this.userInfo = JSON.parse(localStorage.getItem("userInfo"))
    this.role = this.userInfo.role
  },
  methods: {
    // 处理顶部用户下拉框信息
    handleCommand(command) {
      //this.$message('click on item ' + command);
      if (command == "logout") {
        sessionStorage.clear();
        localStorage.clear()
        this.$router.push("/login");
      }
      if(command == "userInfo"){
        if( this.$route.path != '/userInfo' ) this.$router.push("/userInfo")
      }
    },
    //伸缩侧边栏
    showSide() {
      this.hiddenSide = !this.hiddenSide;
    },
    //侧边栏选中更改路径
    activeChange(index) {
      this.activeIndex = index;
    },
  },
};
</script>


<style scoped="scoped">
.el-container {
  height: 100vh;
}

.el-aside {
  /* width: 210px !important;*/
  width: auto !important;
  background-color: #304156;
  height: 100%;
}

.el-header {
  height: 60px;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

/* header头部样式 */
.header-left {
  float: left;
}

.header-left .icon {
  font-size: 26px;
  padding-top: 17px;
  cursor: pointer;
}

.el-dropdown-link {
  cursor: pointer;
}

.header-right {
  float: right;
  line-height: 60px;
}

.header-right img {
  height: 50px;
  vertical-align: middle;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 210px;
  min-height: 400px;
}
</style>
